<!--
 * @Description: 
 * @version: 
 * @Author: m
 * @LastEditors: m
-->
<template>
	<div class="container">
		<van-address-edit
			:area-list="areaList"
			:search-result="searchResult"
			:area-columns-placeholder="['请选择', '请选择', '请选择']"
			@save="onSave"
			@delete="onDelete"
			@change-detail="onChangeDetail"
		/>
	</div>
</template>

<script>
import area from "@/utils/area.js";
import {insert} from "@/api/address.js";
import {setToken} from "@/utils/auth";
export default {
	data() {
		return {
			areaList: area,
			searchResult: [],
		};
	},
	methods: {
		onSave(AddressInfo) {
			this.$toast.success("添加成功!");
			this.$router.push({ path: "/address" });
			insert({
        "contactName": AddressInfo.name,
        "contactTel": AddressInfo.tel,
        "address": AddressInfo.addressDetail
      }).then((res) => {
        console.log(res.data)
        this.$router.push("/address");
      })
			console.log(AddressInfo);
		},
		onDelete() {
			this.$toast.success("删除成功!");
			this.$router.push({ path: "/address" });
			console.log("delete");
		},
		onChangeDetail(val) {
			if (val) {
				this.searchResult = [
					{
						name: "黄龙万科中心",
						address: "杭州市西湖区",
					},
				];
			} else {
				this.searchResult = [];
			}
		},
	},
};
</script>
<style lang="scss" scoped></style>
